<%--
  Created by IntelliJ IDEA.
  User: 15516
  Date: 2020/12/14
  Time: 20:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>这是一个测试jsp</title>
    <script src="js/jquery.min.js"></script>
    <script src="js/echarts.min.js"></script>
</head>
<body>
<!-- 为ECharts准备一个具备大小（宽高）的Dom -->
<div id="main" style="width: 1400px;height:650px;"></div>
<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));
    // 指定图表的配置项和数据

    setTimeout(function () {

        option = {
            title: {
                text: "不同温度下租车情况",

            },

            toolbox: {
                show: true,
                feature: {
                    mark: {
                        show: true
                    },
                    dataView: {
                        show: true,
                        readOnly: true
                    },
                    magicType: {
                        show: false,
                        type: ["line", "bar"]
                    },
                    restore: {
                        show: true
                    },
                    saveAsImage: {
                        show: true
                    }
                }
            },
            legend: {},
            tooltip: {
                trigger: 'axis',
                showContent:false
            },
            dataset: {
                source: [
                    // ['product', '2012', '2013', '2014', '2015', '2016', '2017'],
                    // ['Matcha Latte', 41.1, 30.4, 65.1, 53.3, 83.8, 98.7],
                    // ['Milk Tea', 86.5, 92.1, 85.7, 83.1, 73.4, 55.1],
                    // ['Cheese Cocoa', 24.1, 67.2, 79.5, 86.4, 65.2, 82.5],
                ]
            },
            xAxis: {type: 'category'},
            yAxis: {gridIndex: 0},
            grid: {top: '55%'},
            series: [
                {type: 'line', smooth: true, seriesLayoutBy: 'row'},
                {type: 'line', smooth: true, seriesLayoutBy: 'row'},
                {type: 'line', smooth: true, seriesLayoutBy: 'row'},

                {
                    type: 'pie',
                    id: 'pie',
                    radius: '30%',
                    center: ['50%', '25%'],
                    label: {
                        formatter: '{b}: {@2012} ({d}%)'
                    },
                    encode: {
                        itemName: 'temp',
                        value: '0',
                        tooltip: '0'
                    }
                }
            ]
        };

        myChart.on('updateAxisPointer', function (event) {
            var xAxisInfo = event.axesInfo[0];
            if (xAxisInfo) {
                var dimension = xAxisInfo.value + 1;
                myChart.setOption({
                    series: {
                        id: 'pie',
                        label: {
                            formatter: '{b}: {@[' + dimension + ']} ({d}%)'
                        },
                        encode: {
                            value: dimension,
                            tooltip: dimension
                        }
                    }
                });
            }
        });
        var temps=[];
        var casual=[];
        var registered=[];
        var count=[];

        $.ajax({
            url: 'dts',
            method: "get",
            dataType: "json",
            success: function (data) {
                // alert(JSON.stringify(data));
                if (data){
                    temps.push('temp');
                    casual.push('casual');
                    registered.push('registered');
                    count.push('count');
                    for (var i=0;i<data.length;i++){

                        temps.push(data[i]['temp']);
                    }
                    for (var i=0;i<data.length;i++){
                        casual.push(data[i]['casual']);
                    }
                    for (var i=0;i<data.length;i++){
                        registered.push(data[i]['registered']);
                    }
                    for (var i=0;i<data.length;i++){
                        count.push(data[i]['count']);
                    }
                    alert(temps);
                    myChart.setOption({
                        dataset: {
                            source: [
                               temps,
                               casual,
                               registered,
                               count
                            ]
                        }
                    })
                }

            },
            error: function (errMsg) {
                console.error(errMsg)
            }

        });

        myChart.setOption(option);

    });

    // 使用刚指定的配置项和数据显示图表。

</script>
</body>
</html>
